
/*
 * @项目名称: 模板开发
 * @FilePath: /meek/src/lyr/image/singlecanvas.js
 * @Author: kongxueyang@datatang.com
 * @Date: 2021-02-03T19:03:50+08:00
 * @LastEditors: kongxueyang@datatang.com
 * @LastEditTime: 2021-02-03T19:03:50+08:00
 * Copyright (c) 2018-2022 
 */
                                                    
/**
 * Created by zhangyong on 2017/6/6.
 */

import BaseImage from '../../core/baseimage'
import {ImageState} from './imagestate'
import Obj from '../../utils/obj'
import {ExtentUtil} from '../../geometry/support/extentutil'
import {EventType} from '../../meek/eventtype'

import {listenOnce, unlistenByKey} from '../../core/eventmanager'
import {getUid} from '../../utils/counter'

export default class SingleImage extends BaseImage {
  
  constructor (extent, resolution, pixelRatio, attributions, canvas) {
    
    super(extent, resolution, pixelRatio, ImageState.IDLE,
      attributions)

  
    /**
     * @private
     * @type {HTMLCanvasElement|Image|HTMLVideoElement}
     */
    this.domImage = canvas;
  
    /**
     * @private
     * @type {Object.<number, (HTMLCanvasElement|Image|HTMLVideoElement)>}
     */
    this._imageByContext = {}
  
    /**
     * @private
     * @type {Array.<EventsKey>}
     */
    this._imageListenerKeys = null
  
    /**
     * @protected
     * @type {ImageState}
     */
    this.state = ImageState.LOADED
  
    /**
     * @private
     * @type {ImageLoadFunctionType}
     */

    if (this.resolution === undefined) {
      this.resolution = ExtentUtil.getHeight(this.extent) / this.getDomImage().height
    }

    this.changed();
  }
  
  /**
   * @inheritDoc
   * @api
   */
  getDomImage (opt_context) {
    return this._domImage
  }
  
  /**
   * @param {HTMLCanvasElement|Image|HTMLVideoElement} image Image.
   */
  set domImage (value) {
    this._domImage = value
  }

}

